#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time    : 2023/9/5 16:59
# @Author  : jiangwei
# @Site    : 
# @File    : run_temu_seller.py
# @Software: PyCharm
import sys
import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(BASE_DIR)

from datetime import datetime
from spider.temu_shop.execute_temu_seller import temu_seller_goods, temu_seller_xmen, temu_seller_picture, temu_seller_suborder
from apscheduler.schedulers.blocking import BlockingScheduler
from spider.temu_shop.login_temu_driss import login_temu_driss
from spider.temu_shop.login_temu_xmen_driss import login_temu_xmen_driss

# 登录temu seller
def run_temu_login():
    print("=====temu seler login start：{}=====".format(datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
    login_temu_driss()
    print("=====temu seler login end：{}=====".format(datetime.now().strftime('%Y-%m-%d %H:%M:%S')))

# 登录temu_xmen
def run_temu_xmen_login():
    print("=====temu seler login start：{}=====".format(datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
    login_temu_xmen_driss()
    print("=====temu seler login end：{}=====".format(datetime.now().strftime('%Y-%m-%d %H:%M:%S')))


def run_temu_seller_goods():
    """
    执行按天采集temu卖家视角价格
    :return:
    """
    print("=====开始执行temu seler采集：{}=====".format(datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
    temu_seller_goods()
    temu_seller_xmen()
    # temu_seller_picture()  # 2024年12月23号下线
    # temu_seller_suborder()
    print("=====结束执行temu seler采集：{}=====".format(datetime.now().strftime('%Y-%m-%d %H:%M:%S')))


def run_temu_suborder():
    """
    备货单数据采集
    :return:
    """
    temu_seller_suborder()  # 2024年12月23号下线


scheduler = BlockingScheduler(job_defaults={'misfire_grace_time': 15 * 60})
scheduler.add_job(func=run_temu_login, trigger='cron', day="*/1", hour="*/1", minute="50",
                  timezone='Asia/Shanghai')  # 每天定时执行登录
scheduler.add_job(func=run_temu_xmen_login(), trigger='cron', day="*/1", hour="*/1", minute="56",
                  timezone='Asia/Shanghai')  # 每天定时执行登录

scheduler.add_job(func=run_temu_seller_goods, trigger='cron', day="*/1", hour="8-9", minute="10",
                  timezone='Asia/Shanghai')  # 每天定时执行采集


# scheduler.add_job(func=run_temu_suborder, trigger='cron', day="*/1", hour="9", minute="30",
#                   timezone='Asia/Shanghai')  # 每天定时执行采集
# scheduler.add_job(func=run_temu_suborder, trigger='cron', day="*/1", hour="9", minute="37",
#                   timezone='Asia/Shanghai')  # 每天定时执行采集
# scheduler.add_job(func=run_temu_suborder, trigger='cron', day="*/1", hour="9", minute="39",
#                   timezone='Asia/Shanghai')  # 每天定时执行采集

scheduler.start()





